﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

namespace _077.ASP.NET_Core_WebAPI入门.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestController : ControllerBase
    {

        [HttpPost]
        public string SaveNote(SaveNoteRequest req)
        {
            string filename = $"{req.Title}.txt";
            System.IO.File.WriteAllText(filename, req.Content);
            return filename;
        }

        [HttpGet]
        public Person GetPerson()
        {
            return new Person("fzn", new DateTime(2000, 1, 2));
        }

        [HttpGet]
        public ActionResult<Person> GeActionResult()
        {
            return NotFound("没有找到");
        }

        /**
         * 参数获取 URL
         */
        [HttpGet("{i1:int}/{i2:int}")]
        public int Multi(int i1, int i2)
        {
            return i1 * i2;
        }


        /**
         * ？ & 的形式
         */
        [HttpGet]
        public int Multi2([FromQuery(Name = "a")] int i1, int i2)
        {
            return i1 * i2;
        }

        /**
         * 参数不一致的问题
         */
        [HttpGet("{schoolName}/{classNo}")]
        public ActionResult<string> GetStudents(string schoolName,[FromRoute(Name = "classNo")] string className)
        {
            return schoolName + " " + className;
        }

    }
}
